import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *求100以内素数，求出后休眠一个随机时间
 */

public class OneThread extends Thread{
    public OneThread() {
        super();
    }
    public OneThread(String str) {
        super(str);
    }
    public void run() {
        System.out.println("100以内素数:1");
        System.out.println("100以内素数:2");
        System.out.println("100以内素数:3");
        for(int i = 4; i <= 100; i++) {
            for(int j = 2; j <= i/2; j++) {
                if(i%j == 0) {
                    break;
                }
                if(j == i/2) {
                    System.out.println("100以内素数:" + i);
                }
            }
        }
        long time = (long)(1000+Math.random()*3000);
        System.out.println("100以内素数计算完毕，该线程将休眠" + time +"毫秒");
        try {
            super.sleep(time);
        } catch (InterruptedException ex) {
            Logger.getLogger(OneThread.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("100以内素数，该线程结束");
    }
}